﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using Codeplex.Reactive;
using Microsoft.Practices.Prism.Events;
using Codeplex.KinkumaFramework;
using System.Reactive.Linq;
using HelloWorld.Common;
using System.Diagnostics;

namespace HelloWorld.DisplayModule
{
    [Export]
    public class DisplayModel
    {
        public IEventAggregator EventAggregator { get; private set; }

        public ReactiveProperty<string> DisplayText { get; private set; }

        [ImportingConstructor]
        public DisplayModel(IEventAggregator ea)
        {
            this.EventAggregator = ea;

            this.DisplayText = this.EventAggregator
                .ToObservable<Message>()
                .Select(m => m.Text)
                .ToReactiveProperty(mode: ReactivePropertyMode.RaiseLatestValueOnSubscribe);
            this.EventAggregator.GetEvent<CompositePresentationEvent<Message>>()
                .Subscribe(m => Debug.WriteLine("DEBUG: " + m.Text));
        }
    }
}
